#include <sys/syscall.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define __NR_logcalls   
#define __NR_limopen    
#define __NR_limexec   

int limexec(char * path)
{
        return (int) syscall(__NR_limexec, path);
}

int limopen(char * path)
{
        return (int) syscall(__NR_limopen, path);
}

int main (int argc, char *argv[])
{
        if (argc != 5)
        {
                printf("Usage: plimit [limit-open-path] [limit-exe-path] [prog] [arg] \n");
                exit(0);
        }

        if ( limexec(argv[2]) == 0 && limopen(argv[1]) == 0  )
        {
                printf("pid: %d\n", getpid());
                printf("paths limited to (open) %s\n", argv[1]);
                printf("paths limited to (exec) %s\n", argv[2]);
        }
        else
        {
                printf("plimit failed\n");
                exit(0);
        }

        char * prog = argv[3];         
        char * arg = argv[4];           
        char * args_n[3];

        args_n[0] = prog;
        args_n[1] = arg;
        args_n[2] = NULL;

        execvp( argv[3], args_n );

        exit(0);
}